#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.IO;
using Microsoft.Xna.Framework.Audio;
using Tomahawk.Resources.Audio;
using System.Collections;
#endregion

namespace Tomahawk.Runtime.Audio
{
    /// <summary>
    /// This is the audio manager of the game
    /// </summary>
    public class AudioManager
    {
        #region CategoryCollection
        public class CategoryCollection
        {
            protected AudioManager audioManager = null;

            public CategoryCollection(AudioManager audioManager)
            {
                this.audioManager = audioManager;
            }

            public AudioCategory this[string index]
            {
                get
                {
                    return audioManager.audioEngine.GetCategory(index);
                }
            }
        }
        #endregion

        #region VariableCollection
        public class VariableCollection
        {
            protected AudioManager audioManager = null;

            public VariableCollection(AudioManager audioManager)
            {
                this.audioManager = audioManager;
            }

            public float this[string index]
            {
                get
                {
                    return audioManager.audioEngine.GetGlobalVariable(index);
                }

                set
                {
                    audioManager.audioEngine.SetGlobalVariable(index, value);
                }
            }
        }
        #endregion
        
        #region Properties
        private AudioEngine audioEngine = null;
        public AudioEngine AudioEngine { get { return audioEngine; } }
        private CategoryCollection categories = null;
        public CategoryCollection Categories { get { return categories; } }
        private VariableCollection variables = null;
        public VariableCollection Variables { get { return variables; } }

        private AudioListener audioListener = new AudioListener();
        public AudioListener AudioListener { get { return audioListener; } set { audioListener = value; } }
        #endregion

        #region Initialization
        public AudioManager(string settingsFile)
        {
            if (settingsFile != "")
            {
                audioEngine = new AudioEngine(settingsFile);
                categories = new CategoryCollection(this);
                variables = new VariableCollection(this);
            }

            if (audioEngine != null)
            {
                AudioBankReader.OnInitAudioBank += new AudioBankReader.InitAudioBankDelegate(OnInitAudioBank);
            }
        }

        public bool OnInitAudioBank(AudioBank audioBank)
        {
            return audioBank.Initialize(audioEngine);
        }
        #endregion

        #region Update
        public void Update(float elapsedTime)
        {
            if (audioEngine != null)
            {
                audioEngine.Update();
            }
        }
        #endregion
    }
}


